<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<title>Fullset</title>
	<link rel="stylesheet" href="/dep/layui/src/css/layui.css">
	<link rel="stylesheet" href="/src/css/login.css" media="all">
	<style>
		#loginTitle{animation:change 10s linear 0s infinite;font-size:30px;font-weight:700;}
		@keyframes change{0%   {color:#333;}25%{color:#ff0;}50%{color:#f60;}75%{color:#cf0;}100% {color:#f00;}}
	</style>
</head>
<body class="layui-layout-body" style="background-color:#F6F6F6;text-align:center;margin:0 auto;display:flex">
	<div class="layui-layout-login" style="width: 360px; text-align:center;margin:0 auto;padding: 180px 0;">
		<div id ="loginTitle" style="margin: 15px 0;font-size: 32px;letter-spacing:2px;">Fullset</div>
		<div class="layui-form-item" style="position: relative;">
			<label class="user-login-icon layui-icon layui-icon-username"></label>
			<input name="username" type="text" lay-verify="required" placeholder="账号" value=""
					   class="layui-input" style="padding-left: 38px;">
		</div>
		<div class="layui-form-item" style="position: relative;">
			<label class="user-login-icon layui-icon layui-icon-password"></label>
			<input name="password" type="password" lay-verify="required" placeholder="密码"
				   value="" class="layui-input" style="padding-left: 38px;">
		</div>
		<div class="layui-form-item">
			<button class="layui-btn layui-btn-fluid" id="loginBtn" lay-submit lay-filter="loginBtnSubmit">登 录</button>
		</div>
		<div class="layui-footer">
		</div>
	</div>
	<script src="/dep/layui/src/layui.js"></script>
	<script>
		layui.config({
			base: '/src/js/'
		}).use(['form', 'util', 'base'], function () {
			var form = layui.form
				,$ = layui.jquery
				,util = layui.util
				,base = layui.base;
				//登录入口
				form.on('submit(loginBtnSubmit)', function (obj) {
					debugger
					//登录界面传入帐号和密码
					var field = obj.field;
					field.grant_type = 'password';
					field.scope = 'app';
					field.client_id = 'webApp';
					field.client_secret = 'webApp';
					debugger
					$.ajax({
						url: '/authService/oauth/token',
						data: field,
						type: 'POST',
						success: function (data) {
							debugger
							if (data.access_token) {
								debugger
								location.replace('./admin/index.html');
							} else {
								layer.closeAll('loading');
								layer.msg('登录失败，请重试', { icon: 5 });
						
							}
						},
						error: function (xhr) {
							layer.closeAll('loading');
							if (xhr.status == 400) {
								var msgStr = xhr.responseJSON.msg;
								layer.msg(msgStr, { icon: 5 });
							} else if (xhr.status == 500) {
								layer.msg('服务器异常,请联系管理员', { icon: 5 });
							}
							else if (xhr.status == 401) {
								layer.msg('没有访问权限,请联系管理员', { icon: 5 });
							}
							else if (xhr.status == 504) {
								layer.msg('网关服务异常,请联系管理员', { icon: 5 });
							}
						}
					});
					return false;
				});

				//回车事件登录
				$("body").on('keydown', function (event) {
				var event = window.event || event;
				if (event.keyCode == 13) {
					$("#loginBtn").click();
					return false;
				}
				});
	});
	</script>
</body>

</html>